#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.http import HttpResponse
from everlog.weblog import models
from django.shortcuts import render_to_response
from django.shortcuts import redirect
from django.db.models import Q
from django.template import RequestContext
from django.conf import settings
from django.db.models import Count

def globle(request):
    """get the globle settings"""    
    return {
        'site_url': settings.SITE_URL,
        'site_title': settings.SITE_TITLE,
        'tag_line': settings.TAG_LINE,
        'site_media': settings.STATIC_URL,
    }

def page(request):
    """all pages"""
    pages = models.Post.objects.filter(type='page')
    return {
        'pages': pages,
    }

def tag(request):
    """all tags"""
    tags = models.Tag.objects.annotate(Count('post'))
    return {
        'tags': tags,
    }

def archives(request):
    """archives of month"""
    archives = models.Post.objects.filter(type='post').dates('date', 'month',  order='ASC')
    return {
        'archives': archives,
    }

def recent_posts(request):
    """5 latest posts"""
    recent_posts = models.Post.objects.filter(type='post').order_by('-id')[:4]
    return {
        'recent_posts': recent_posts,
    }

def links(request):
    """ all the links """
    links = models.Link.objects.all()
    return {
        'links': links,
    }
